


import sqlite3





#添加学生
def students_add(stu_id,number,password):
    import sqlite3
    # 创建数据库连接
    conn = sqlite3.connect('tables.db')

    # 创建游标
    cursor = conn.cursor()


    cursor.execute(
        "INSERT INTO students (student_id, number, password) VALUES (?, ?, ?)",
        (stu_id, number, password))


    # 提交更改
    conn.commit()

    # 关闭游标和连接
    cursor.close()
    conn.close()
#添加老师
def teachers_add(job_id,number,password):
    import sqlite3
    # 创建数据库连接
    conn = sqlite3.connect('tables.db')

    # 创建游标
    cursor = conn.cursor()

    cursor.execute(
        "INSERT INTO teachers (job_id, number, password) VALUES (?, ?, ?)",
        (job_id, number, password))


    # 提交更改
    conn.commit()

    # 关闭游标和连接
    cursor.close()
    conn.close()

#查找该学号是否被注册（已存在）
def find_student_id(student_id):

    import sqlite3
    # 创建数据库连接
    conn = sqlite3.connect('tables.db')

    # 创建游标
    cursor = conn.cursor()

    try:
        # 执行查询语句
        cursor.execute('SELECT name FROM students WHERE student_id = ?', (student_id,))
        result = cursor.fetchone()
        if result is None:
            return False  # 没有找到学生
        else:
            return True  # 返回T
    except Exception as e:
        print(f"Error occurred: {e}")
    finally:
        conn.close()

#查找该工号是否被注册（已存在）
def find_teacher_id(jod_id):
    import sqlite3
    # 创建数据库连接
    conn = sqlite3.connect('tables.db')

    # 创建游标
    cursor = conn.cursor()


    try:
        # 执行查询语句
        cursor.execute('SELECT name FROM teachers WHERE job_id = ?', (jod_id,))
        result = cursor.fetchone()
        if result is None:

            return False  # 没有找到老师

        else:

            return True  #
    except Exception as e:
        print(f"Error occurred: {e}")
    finally:
        conn.close()



if __name__ == '__main__':

    try:
        get_students_to_class('123')

    except rospy.ROSInterruptException:
    	pass

